/**
 * 
 */
package com.p2p.front.mail;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfig;

import com.p2p.base.model.MailTemplate;
import com.p2p.base.model.Money;
import com.p2p.base.service.EmailService;

import freemarker.template.Configuration;
import freemarker.template.Template;

/**
 * @author ricky
 *
 */
@Component
public class TenderMailTemplate extends MailTemplate {

	public static String name = "TenderMail";
	
	@Resource
	private FreeMarkerConfig freemarkerMailConfig;
	
	@Resource
	private EmailService emailService;
	/* (non-Javadoc)
	 * @see com.p2p.base.model.MailTemplate#getTemplateName()
	 */
	@Override
	protected String getTemplateName() {
		return name;
	}

	/* (non-Javadoc)
	 * @see com.p2p.base.model.MailTemplate#doInitTemplate()
	 */
	@Override
	protected void doInitTemplate() {
		try {
			Configuration configuration = this.freemarkerMailConfig.getConfiguration();
			Template tenderMailTemplate = configuration.getTemplate("user/mail/"+name+".ftl");
			
			//String text = this.emailService.getMailText(tenderMailTemplate, model);
			this.setFtlTemplate(tenderMailTemplate);
			this.setFrom("leiruiqi@yiqihao.com");
			this.setSubject("测试邮件");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new RuntimeException("error happens", e);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new RuntimeException("error happens", e);
		}
		

	}

}
